package cn.edu.ustc.multicore.exercise.ch4;

public class CriticalSection {
	
	private  final static CriticalSection  instance = new CriticalSection();
	private volatile long  accessTimes = 0l;
	
	private CriticalSection(){
		accessTimes = 0l;
	}
	public static CriticalSection getInstance(){
		return instance;
	}
	public long getAccessTimes() {
		return accessTimes;
	}
	/**
	 * need a lock to do synchronization 
	 */
	public void access(){
		accessTimes ++;
	}
	public synchronized void reset(){
		accessTimes = 0l;
	}
}
